<?php
if(!defined('IN_WOGU')) {
	exit('Access Denied');
}

class Request
{
	public $module = null;
	public $controller = null;
	public $action = null;
	protected $_dispatched = false;
	protected $_params = array();

	public function __construct() {
		if(!get_magic_quotes_gpc()) {
			$_POST = new_addslashes($_POST);
			$_GET = new_addslashes($_GET);
			$_REQUEST = new_addslashes($_REQUEST);
			$_COOKIE = new_addslashes($_COOKIE);
		}

		$this->_params = $_REQUEST;
	}

	public function get_module() {
		return $this->module;
	}

	public function set_module($val) {
		$this->module = strtolower(new_htmlspecialchars($val));
	}

	public function get_controller() {
		$controller = ucfirst($this->module) . '_';
		$parts = explode('_', $this->controller);
		foreach ($parts as $v) {
			$controller .= ucfirst($v);
		}
		$controller .= 'Controller';
		return  $controller;
	}

	public function set_controller($val) {
		$this->controller = strtolower(new_htmlspecialchars($val));
	}

	public function get_action() {
		$parts = explode('_', $this->action);
		$action = $parts[0];
		$len = count($parts);
		if($len > 1) {
			for($i = 1; $i < $len; $i++) {
				$action .= ucfirst($parts[$i]);
			}
		}
		
		return $action . 'Action';
	}

	public function set_action($val) {
		$this->action = strtolower(new_htmlspecialchars($val));
	}

	public function setDispatched($b) {
		$this->_dispatched = $b;
	}

	public function isDispatched() {
		return $this->_dispatched;
	}

	public function setParam($key, $val) {
		$this->_params[$key] = $val;
	}

	public function getParam($key) {
		return isset($this->_params[$key]) ? $this->_params[$key] : '';
	}

	public function getParams() {
		return $this->_params;
	}

	public function setParams($array) {
		foreach($array as $key => $val) {
			$this->_params[$key] = $val;
		}
	}
}